package com.lm;

import com.lm.pojo.User;
import com.lm.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Date;
import java.util.List;

/**
 * 参考链接:https://www.cnblogs.com/tjlstudy/p/13038508.html
 * 导入spring-test maven包，注意与主文件的jar冲突，版本要一致
 * spring使用JUnit测试，@Autowired无法注入原因
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applcationContext.xml")  //表示在编译完成后在类路径下的beean.xml文件
public class UserTest1 {

    @Autowired
    private UserService userService;

    @Test
    public void test_getUserList() throws Exception {
        List<User> userList = userService.getUserList();
        for(User user: userList){
            System.out.println(user);
        }
    }

    @Test
    public void test_getUserById() throws Exception {
        User user = userService.getUserById(1);
        System.out.println("测试：" + user);
    }

    @Test
    public void test_testTransaction() throws Exception {
        User user = new User();
        user.setId(12);
        user.setUsername("测试");
        user.setAge(30);
        user.setCreateTime(new Date());
        userService.testTransaction(user);
        System.out.println("测试user：" + user);
    }


}
